﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;


namespace BA2009.Utility
{
    public class ExceptionManager
    {
        //public static void Handle(Window owner, Exception ex)
        //{
        //    //Message msg = new Message();
        //    //msg.Confirm = CONFIRM.OK;
        //    //msg.Content = ex.Message;
        //    //msg.Type = MSG_TYPE.ERROR;

        //    //MessageDialog dialog = new MessageDialog();
        //    //dialog.MessageEntity = msg;
        //    //dialog.Owner = owner;
        //    //dialog.ShowActivated = true;
        //    //dialog.ShowDialog();
        //}

        public static void Handle(Exception ex)
        {
            //Message msg = new Message();
            //msg.Confirm = CONFIRM.OK;
            //msg.Content = ex.Message;
            //msg.Type = MSG_TYPE.ERROR;

            //MessageDialog dialog = new MessageDialog();
            //dialog.MessageEntity = msg;
            //dialog.ShowActivated = true;
            //dialog.ShowDialog();

            LogErrors(ex);
        }

        private static void LogErrors(Exception ex)
        {
             string fileName = string.Concat("D:\\Temp\\", DateTime.Now.ToString("dd_mm_yyyy"), ".txt");
            FileStream fs;
            if (File.Exists(fileName))
                fs = new FileStream(fileName, FileMode.Append);
            else
                fs = new FileStream(fileName, FileMode.CreateNew);


            StreamWriter sw = new StreamWriter(fs);

            sw.WriteLine(DateTime.Now.ToLongDateString() + ":");
            sw.WriteLine("Message: " + ex.Message);
            sw.WriteLine("StackTrace: " + ex.StackTrace);

            sw.WriteLine();
            sw.WriteLine();
            sw.WriteLine();

            sw.Close();
            fs.Close();
        }

        public static void Handle(string p)
        {
            throw new NotImplementedException();
        }
    }
}
